<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Spec::Runner::SpecParser</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Spec::Runner::SpecParser</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/plugins/rspec/lib/spec/runner/spec_parser_rb.html">
                vendor/plugins/rspec/lib/spec/runner/spec_parser.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Parses a spec file and finds the nearest example for a given line number.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000585">consider_example_for_best_match</a>&nbsp;&nbsp;
      <a href="#M000584">consider_example_groups_for_best_match</a>&nbsp;&nbsp;
      <a href="#M000586">is_best_match?</a>&nbsp;&nbsp;
      <a href="#M000582">new</a>&nbsp;&nbsp;
      <a href="#M000587">parse_backtrace</a>&nbsp;&nbsp;
      <a href="#M000583">spec_name_for</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">best_match</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000582" class="method-detail">
        <a name="M000582"></a>

        <div class="method-heading">
          <a href="#M000582" class="method-signature">
          <span class="method-name">new</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000582-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000582-source">
<pre>
   <span class="ruby-comment cmt"># File vendor/plugins/rspec/lib/spec/runner/spec_parser.rb, line 7</span>
7:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>
8:         <span class="ruby-ivar">@best_match</span> = {}
9:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000583" class="method-detail">
        <a name="M000583"></a>

        <div class="method-heading">
          <a href="#M000583" class="method-signature">
          <span class="method-name">spec_name_for</span><span class="method-args">(file, line_number)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000583-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000583-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/rspec/lib/spec/runner/spec_parser.rb, line 11</span>
11:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">spec_name_for</span>(<span class="ruby-identifier">file</span>, <span class="ruby-identifier">line_number</span>)
12:         <span class="ruby-identifier">best_match</span>.<span class="ruby-identifier">clear</span>
13:         <span class="ruby-identifier">file</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">file</span>)
14:         <span class="ruby-constant">Spec</span><span class="ruby-operator">::</span><span class="ruby-constant">Runner</span>.<span class="ruby-identifier">options</span>.<span class="ruby-identifier">example_groups</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">example_group</span><span class="ruby-operator">|</span>
15:           <span class="ruby-identifier">consider_example_groups_for_best_match</span> <span class="ruby-identifier">example_group</span>, <span class="ruby-identifier">file</span>, <span class="ruby-identifier">line_number</span>
16: 
17:           <span class="ruby-identifier">example_group</span>.<span class="ruby-identifier">examples</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">example</span><span class="ruby-operator">|</span>
18:             <span class="ruby-identifier">consider_example_for_best_match</span> <span class="ruby-identifier">example</span>, <span class="ruby-identifier">example_group</span>, <span class="ruby-identifier">file</span>, <span class="ruby-identifier">line_number</span>
19:           <span class="ruby-keyword kw">end</span>
20:         <span class="ruby-keyword kw">end</span>
21:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">best_match</span>[<span class="ruby-identifier">:example_group</span>]
22:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">best_match</span>[<span class="ruby-identifier">:example</span>]
23:             <span class="ruby-node">&quot;#{best_match[:example_group].description} #{best_match[:example].description}&quot;</span>
24:           <span class="ruby-keyword kw">else</span>
25:             <span class="ruby-identifier">best_match</span>[<span class="ruby-identifier">:example_group</span>].<span class="ruby-identifier">description</span>
26:           <span class="ruby-keyword kw">end</span>
27:         <span class="ruby-keyword kw">else</span>
28:           <span class="ruby-keyword kw">nil</span>
29:         <span class="ruby-keyword kw">end</span>
30:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000585" class="method-detail">
        <a name="M000585"></a>

        <div class="method-heading">
          <a href="#M000585" class="method-signature">
          <span class="method-name">consider_example_for_best_match</span><span class="method-args">(example, example_group, file, line_number)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000585-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000585-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/rspec/lib/spec/runner/spec_parser.rb, line 45</span>
45:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">consider_example_for_best_match</span>(<span class="ruby-identifier">example</span>, <span class="ruby-identifier">example_group</span>, <span class="ruby-identifier">file</span>, <span class="ruby-identifier">line_number</span>)
46:         <span class="ruby-identifier">parsed_backtrace</span> = <span class="ruby-identifier">parse_backtrace</span>(<span class="ruby-identifier">example</span>.<span class="ruby-identifier">implementation_backtrace</span>)
47:         <span class="ruby-identifier">parsed_backtrace</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">example_file</span>, <span class="ruby-identifier">example_line</span><span class="ruby-operator">|</span>
48:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">is_best_match?</span>(<span class="ruby-identifier">file</span>, <span class="ruby-identifier">line_number</span>, <span class="ruby-identifier">example_file</span>, <span class="ruby-identifier">example_line</span>)
49:             <span class="ruby-identifier">best_match</span>.<span class="ruby-identifier">clear</span>
50:             <span class="ruby-identifier">best_match</span>[<span class="ruby-identifier">:example_group</span>] = <span class="ruby-identifier">example_group</span>
51:             <span class="ruby-identifier">best_match</span>[<span class="ruby-identifier">:example</span>] = <span class="ruby-identifier">example</span>
52:             <span class="ruby-identifier">best_match</span>[<span class="ruby-identifier">:line</span>] = <span class="ruby-identifier">example_line</span>
53:           <span class="ruby-keyword kw">end</span>
54:         <span class="ruby-keyword kw">end</span>
55:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000584" class="method-detail">
        <a name="M000584"></a>

        <div class="method-heading">
          <a href="#M000584" class="method-signature">
          <span class="method-name">consider_example_groups_for_best_match</span><span class="method-args">(example_group, file, line_number)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000584-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000584-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/rspec/lib/spec/runner/spec_parser.rb, line 34</span>
34:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">consider_example_groups_for_best_match</span>(<span class="ruby-identifier">example_group</span>, <span class="ruby-identifier">file</span>, <span class="ruby-identifier">line_number</span>)
35:         <span class="ruby-identifier">parsed_backtrace</span> = <span class="ruby-identifier">parse_backtrace</span>(<span class="ruby-identifier">example_group</span>.<span class="ruby-identifier">registration_backtrace</span>)
36:         <span class="ruby-identifier">parsed_backtrace</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">example_file</span>, <span class="ruby-identifier">example_line</span><span class="ruby-operator">|</span>
37:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">is_best_match?</span>(<span class="ruby-identifier">file</span>, <span class="ruby-identifier">line_number</span>, <span class="ruby-identifier">example_file</span>, <span class="ruby-identifier">example_line</span>)
38:             <span class="ruby-identifier">best_match</span>.<span class="ruby-identifier">clear</span>
39:             <span class="ruby-identifier">best_match</span>[<span class="ruby-identifier">:example_group</span>] = <span class="ruby-identifier">example_group</span>
40:             <span class="ruby-identifier">best_match</span>[<span class="ruby-identifier">:line</span>] = <span class="ruby-identifier">example_line</span>
41:           <span class="ruby-keyword kw">end</span>
42:         <span class="ruby-keyword kw">end</span>
43:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000586" class="method-detail">
        <a name="M000586"></a>

        <div class="method-heading">
          <a href="#M000586" class="method-signature">
          <span class="method-name">is_best_match?</span><span class="method-args">(file, line_number, example_file, example_line)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000586-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000586-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/rspec/lib/spec/runner/spec_parser.rb, line 57</span>
57:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">is_best_match?</span>(<span class="ruby-identifier">file</span>, <span class="ruby-identifier">line_number</span>, <span class="ruby-identifier">example_file</span>, <span class="ruby-identifier">example_line</span>)
58:         <span class="ruby-identifier">file</span> <span class="ruby-operator">==</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">example_file</span>) <span class="ruby-operator">&amp;&amp;</span>
59:         <span class="ruby-identifier">example_line</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">line_number</span> <span class="ruby-operator">&amp;&amp;</span>
60:         <span class="ruby-identifier">example_line</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">best_match</span>[<span class="ruby-identifier">:line</span>].<span class="ruby-identifier">to_i</span>
61:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000587" class="method-detail">
        <a name="M000587"></a>

        <div class="method-heading">
          <a href="#M000587" class="method-signature">
          <span class="method-name">parse_backtrace</span><span class="method-args">(backtrace)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000587-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000587-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/rspec/lib/spec/runner/spec_parser.rb, line 63</span>
63:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_backtrace</span>(<span class="ruby-identifier">backtrace</span>)
64:         <span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">collect</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">trace_line</span><span class="ruby-operator">|</span>
65:           <span class="ruby-identifier">split_line</span> = <span class="ruby-identifier">trace_line</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">':'</span>)
66:           [<span class="ruby-identifier">split_line</span>[<span class="ruby-value">0</span>], <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">split_line</span>[<span class="ruby-value">1</span>])]
67:         <span class="ruby-keyword kw">end</span>
68:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>